package com.company.dcm.server.tcp;

import com.company.dcm.common.SpringBeanUtil;
import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @Author: 王泽同
 * @Description:
 */
//@Slf4j
//@Component
//public class VertxTcpStarter implements ApplicationRunner{
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        new VertxTcpServer().doStart(9989);
//
//        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
//            log.info("begin stop vertx");
//            Vertx vertx= SpringBeanUtil.getBean(Vertx.class);
//            CountDownLatch countDownLatch=new CountDownLatch(1);
//            vertx.close(res->{
//                countDownLatch.countDown();
//            });
//            try {
//                countDownLatch.await(30, TimeUnit.SECONDS);
//                log.info("stop vertx success");
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }));
//    }
//}
